 <?php
	//首页
	class IndexAction extends Action {
		/**2014-4-25
		 * 吕春城
		 * 首页显示
		 * */
		public function index() {

			$result = $this->GetAverageScore ();
			$this->assign ( 'voteclass', $result ); //赋值到模板
			$result=$this->GetContent();//文章内容
			$this->assign('content',$result);
			$this->StoreLimitTosession();
			$this->display ();
		}

		/**提取后台平均数据
		 * 2014-4-25
		 * */
		private function GetAverageScore() {
			$sql = sprintf ( "select SUM(item_score) as score,SUM(item_num) as num ,vote_class.class_ID,class_name,class_image,class_keyword from vote_item,vote_class where vote_item.class_ID=vote_class.class_ID  GROUP BY class_ID ORDER BY  vote_class.class_order desc " );
			$result = M ()->query ( $sql );

            foreach ( $result as $key => $value ) {
				$result [$key] ['average'] = number_format ( $value ['score'] / $value ['num'], 2 ); //保留两位小数
			}
			return $result;
		}
		private function  GetContent()
		{
			$sql="SELECT  message_content from vote_message";
			$result=M()->query($sql);
			return  $result[0]['message_content'];
		}
		/*将限制存储于session方便比较*/
		private  function  StoreLimitTosession()
		{
			$sql='select votetime_start as start,votetime_end as end, limit_times as times from vote_message where message_ID=1 ';
		    $result=M()->query($sql);
		    $start=$result[0]['start'];
		    $end=$result[0]['end'];
		    $count=$result[0]['times'];
		    session('start',$start);//开始时间
		    session('end',$end); //结束时间
		    session('count',$count);  //每个小项限制投票次数
		}
	}
	
	
	
	
	
	
	
	